from django.views.generic.list import ListView
from django.views.generic.edit import CreateView, UpdateView, DeleteView
from position.models import Position
from position.models import Categories

class ListPositionView(ListView):
    model = Position
    queryset = Position.objects.all().order_by("-pk")
    def get_context_data(self, **kwargs):
        queryset = Position.objects.all().order_by("-pk")
        s = ""
        count = 0
        for po in queryset:
            s += "ar[%d] = new Array(%5.5f, %5.5f);\n" % (count, po.point_latitude, po.point_longitude, )
            count = count+1
        print s
        # Call the base implementation first to get a context
        context = super(ListPositionView, self).get_context_data(**kwargs)
        # Add in a QuerySet of all the books
        context['arstring'] = s
        return context
    
    

class CreatePositionView(CreateView):
    model = Position
    success_url = "/position/"

class UpdatePositionView(UpdateView):
    model = Position
    success_url = "/position/"

class DeletePositionView(DeleteView):
    model = Position
    success_url = "/position/"

